using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using NetWorkMsg;

namespace NetMsg.App
{
    // 商品类型
    public enum AppType
    {
        Invalid,
        // 地图
        Map,
        // 蛋
        Egg,
        // 聊天
        Chat,
        // 应用商店
        AppStore,
        // 系统升级
        WishMission,
        // 电话
        Phone,
        // 喂养
        Breed,
        // 决斗王
        Duel,
        // 设置
        SIMSet,
        // 败家
        Buy,
        // 音乐
        Music,
        // 壁纸
        Wallpaper,
        // 平行世界
        ParallelWorld,
        // 孵化
        Hatch,
        // 系统升级
        Upgrade,
        End,
    }
    
    // 玩家自己的评价
    public class SelfEvaluateInfo : IUnPackable
    {
        public int Star;
        public int Time;
        public string Describe;
        
        public void UnPack(MemoryStream stream)
        {
            UnPackAuxiliary.Read(stream, out uint var0);
            Star = (int)var0;
            UnPackAuxiliary.Read(stream, out uint var1);
            Time = (int)var1;
            UnPackAuxiliary.Read(stream, out Describe);
        }
    }
    
    // App的附加信息
    public class AppExtraInfo : IPackable, IUnPackable
    {
        public int Id;
        // 配置Id
        public int CfgId;
        
        public void Pack(MemoryStream stream)
        {
            PackAuxiliary.Write(stream, (uint)Id);
            PackAuxiliary.Write(stream, (uint)CfgId);
        }
        
        public void UnPack(MemoryStream stream)
        {
            UnPackAuxiliary.Read(stream, out uint var0);
            Id = (int)var0;
            UnPackAuxiliary.Read(stream, out uint var1);
            CfgId = (int)var1;
        }
    }
    
    // 商品信息
    public class AppInfo : IUnPackable
    {
        // 商品名称，为空则取配置
        public string Name;
        public int AppId;
        public int CfgId;
        public AppExtraInfo Extra;
        public int Level;
        public SelfEvaluateInfo Evaluate;
        
        public void UnPack(MemoryStream stream)
        {
            UnPackAuxiliary.Read(stream, out Name);
            UnPackAuxiliary.Read(stream, out uint var0);
            AppId = (int)var0;
            UnPackAuxiliary.Read(stream, out uint var1);
            CfgId = (int)var1;
            UnPackAuxiliary.Read(stream, out bool var2);
            if(var2)
            {
                Extra = new AppExtraInfo();
                Extra.UnPack(stream);
            }
            UnPackAuxiliary.Read(stream, out uint var3);
            Level = (int)var3;
            UnPackAuxiliary.Read(stream, out bool var4);
            if(var4)
            {
                Evaluate = new SelfEvaluateInfo();
                Evaluate.UnPack(stream);
            }
        }
    }
    
    public class AppSetInfo : IUnPackable
    {
        public int SystemLevel;
        public List<AppInfo> Apps;
        
        public void UnPack(MemoryStream stream)
        {
            UnPackAuxiliary.Read(stream, out uint var0);
            SystemLevel = (int)var0;
            UnPackAuxiliary.Read(stream, out uint var1);
            Apps = new List<AppInfo>((int)var1);
            for(var i = 0; i < var1; ++i)
            {
                var var2 = new AppInfo();
                var2.UnPack(stream);
                Apps.Add(var2);
            }
        }
    }
    
    public class InstallQ : IServerCallbackable
    {
        public int CfgId;
        public AppExtraInfo Extra;
        
        public uint UnPackableId => 4;
        public uint PackableId => 4;
        
        public void Pack(MemoryStream stream)
        {
            PackAuxiliary.Write(stream, 4u);
            PackAuxiliary.Write(stream, (uint)CfgId);
            var var3 = Extra != null;
            PackAuxiliary.Write(stream, var3);
            if(var3)
                Extra.Pack(stream);
        }
    }
    
    public enum InstallResult
    {
        Success,
        // 重复安装
        Again,
        // 金币不足
        NeedMoreGold,
        // 系统等级不够
        NeedSystemLevel,
    }
    
    public class InstallP : IUnPackable
    {
        public int AppId;
        public int CfgId;
        public AppExtraInfo Extra;
        public InstallResult Result;
        
        public const uint Sid = 4;
        
        public void UnPack(MemoryStream stream)
        {
            UnPackAuxiliary.Read(stream, out uint var0);
            AppId = (int)var0;
            UnPackAuxiliary.Read(stream, out uint var1);
            CfgId = (int)var1;
            UnPackAuxiliary.Read(stream, out bool var2);
            if(var2)
            {
                Extra = new AppExtraInfo();
                Extra.UnPack(stream);
            }
            UnPackAuxiliary.Read(stream, out uint var3);
            Result = (InstallResult)var3;
        }
    }
    
    public struct RemoveAppQ : IIdPackable
    {
        public int AppId;
        
        public uint PackableId => 5;
        
        public void Pack(MemoryStream stream)
        {
            PackAuxiliary.Write(stream, 5u);
            PackAuxiliary.Write(stream, (uint)AppId);
        }
    }
    
    public class EvaluateQ : IIdPackable
    {
        public int CfgId;
        public int Star;
        public string Describe;
        
        public uint PackableId => 6;
        
        public void Pack(MemoryStream stream)
        {
            PackAuxiliary.Write(stream, 6u);
            PackAuxiliary.Write(stream, (uint)CfgId);
            PackAuxiliary.Write(stream, (uint)Star);
            PackAuxiliary.Write(stream, Describe);
        }
    }
    
    public class EvaluateInfo : IUnPackable
    {
        public long PlayerId;
        public string Name;
        public int HeadIndex;
        public int Star;
        public string Describe;
        public int Time;
        
        public void UnPack(MemoryStream stream)
        {
            UnPackAuxiliary.Read(stream, out ulong var0);
            PlayerId = (long)var0;
            UnPackAuxiliary.Read(stream, out Name);
            UnPackAuxiliary.Read(stream, out uint var1);
            HeadIndex = (int)var1;
            UnPackAuxiliary.Read(stream, out uint var2);
            Star = (int)var2;
            UnPackAuxiliary.Read(stream, out Describe);
            UnPackAuxiliary.Read(stream, out uint var3);
            Time = (int)var3;
        }
    }
    
    public class AppStoreInfo : IUnPackable
    {
        public int CfgId;
        // 评价个数
        public int Number;
        // 总评分
        public int Star;
        public List<EvaluateInfo> Evaluates;
        
        public void UnPack(MemoryStream stream)
        {
            UnPackAuxiliary.Read(stream, out uint var0);
            CfgId = (int)var0;
            UnPackAuxiliary.Read(stream, out uint var1);
            Number = (int)var1;
            UnPackAuxiliary.Read(stream, out uint var2);
            Star = (int)var2;
            UnPackAuxiliary.Read(stream, out uint var3);
            Evaluates = new List<EvaluateInfo>((int)var3);
            for(var i = 0; i < var3; ++i)
            {
                var var4 = new EvaluateInfo();
                var4.UnPack(stream);
                Evaluates.Add(var4);
            }
        }
    }
    
    public struct GetStoreAppInfoQ : IServerCallbackable
    {
        public int CfgId;
        
        public uint UnPackableId => 5;
        public uint PackableId => 7;
        
        public void Pack(MemoryStream stream)
        {
            PackAuxiliary.Write(stream, 7u);
            PackAuxiliary.Write(stream, (uint)CfgId);
        }
    }
    
    public class GetStoreAppInfoP : IUnPackable
    {
        public AppStoreInfo Info;
        
        public const uint Sid = 5;
        
        public void UnPack(MemoryStream stream)
        {
            Info = new AppStoreInfo();
            Info.UnPack(stream);
        }
    }
    
    public enum UpgradeAppResult
    {
        // 成功
        Success,
        // 异常
        Invalid,
        // 没有找到app
        NotFound,
        // 金币不够
        NeedGold,
        // 系统等级不够
        NeedSystemLevel,
    }
    
    // App升级
    public class UpgradeAppQ : IIdPackable
    {
        public int AppId;
        
        public uint PackableId => 8;
        
        public void Pack(MemoryStream stream)
        {
            PackAuxiliary.Write(stream, 8u);
            PackAuxiliary.Write(stream, (uint)AppId);
        }
    }
    
    public class UpgradeAppP : IUnPackable
    {
        public UpgradeAppResult Result;
        
        public const uint Sid = 6;
        
        public void UnPack(MemoryStream stream)
        {
            UnPackAuxiliary.Read(stream, out uint var0);
            Result = (UpgradeAppResult)var0;
        }
    }
    
    public class OpenAppQ : IIdPackable
    {
        // 打开的APp
        public int CfgId;
        
        public uint PackableId => 9;
        
        public void Pack(MemoryStream stream)
        {
            PackAuxiliary.Write(stream, 9u);
            PackAuxiliary.Write(stream, (uint)CfgId);
        }
    }
    
    public class CloseAppQ : IIdPackable
    {
        public int CfgId;
        
        public uint PackableId => 10;
        
        public void Pack(MemoryStream stream)
        {
            PackAuxiliary.Write(stream, 10u);
            PackAuxiliary.Write(stream, (uint)CfgId);
        }
    }
    
    public enum AppEnum
    {
        InstallP,
        GetStoreAppInfoP,
        UpgradeAppP,
    }
}
